package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.EditFlightView;

/**
 * use case controller to edit a flight search
 * @author group2
 */
public class UCEditFlightSearch implements UCController {

    private EditFlightView editView = new EditFlightView();
    private Flight f;// = new Flight();

    /**
     * sets view and flight
     * @param eView
     * @param fl
     */
    public UCEditFlightSearch(EditFlightView eView, Flight fl) {
        editView = eView;
        f = fl;
    }

    @Override
    public void run() {
        //Search database for flight number
        //returns flight
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(editView.getFlightNum());

        if (f.getFlightNum().equals(null)) //if flight doesn't exist
        {
            editView.resetFlightNum();
            editView.errorFlightNum(); //show error message
        } else {
            editView.showFlightDetails(f); //else display details
        }

    }
    ;
}
